Listing 2 shows how to create a vector data stream for a single path. The path has four on-curve points and two off-curve points. These points specify two curves and one straight line, as shown in Figure 58 . In addition to an atom for the path, the data stream includes an atom that specifies the fill type of subsequent paths in stream.
Listing 2 vector data stream for a single path
ComponentInstance vectorCodec;
Handle streamH;
Handle pathH;
gxPoint points[6];
Boolean isOnCurve[6];
int i;
long value;
/* open the vector codec component */
OpenADefaultComponent (decompressorComponentType,
kVectorCodecType, &vectorCodec);
/* create a new vector data stream */
CurveCreateVectorStream (vectorCodec, streamH);
value=gxOpenFrameFill;
/* add an atom to the vector data stream that specifies that
subsequent paths are to be drawn with open frame fill */
CurveAddAtomToVectorStream (ci, kCurveFillTypeAtom, sizeof(long),
&value, streamH);
/* specify the points for the path and whether each one is
on the path */
points[0].x = ff(50);
points[0].y = ff(100);
isOnCurve[0] = TRUE;
points[1].x = ff(0);
points[1].y = ff(75);
isOnCurve[1] = FALSE;
points[2].x = ff(50);
points[2].y = ff(50);
isOnCurve[2] = TRUE;
points[3].x = ff(150);
points[3].y = ff(50);
isOnCurve[3] = TRUE;
points[4].x = ff(200);
points[4].y = ff(75);
isOnCurve[4] = FALSE;
points[5].x = ff(150);
points[5].y = ff(100);
isOnCurve[5] = TRUE;
/* create the path and add the points to it */
CurveNewPath (vectorCodec, &pathH);
for (i = 0; i <= 5; i++)
CurveInsertPointIntoPath (vectorCodec, &points[i], pathH,
1, i, isOnCurve[i]);
/* add the path to the vector data stream */
CurveAddPathAtomToVectorStream (vectorCodec, pathH, streamH);
/* mark the end of the vector data stream by adding a
kCurveEndAtom atom to the stream */
CurveAddZeroAtomToVectorStream (vectorCodec, streamH);
/* use the vector codec here to decompress and display the vector data */
/* dispose of stream and path handles when done */
DisposeHandle (streamH);
DisposeHandle (pathH);
Figure 58 A path with six points
| Previous | Chapter Contents | Chapter Top | Next |